
package com.spsy.order.listener;

import com.alibaba.fastjson2.JSON;
import com.alibaba.nacos.shaded.com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.rabbitmq.client.Channel;
import com.spsy.common.vo.NotifyOrderRequest;
import com.spsy.order.api.OrderApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.*;


@Component
@RabbitListener(queues = "2209a_queue_a5")
@Slf4j
public class DirectListener {



    public static final ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("notice-order-pool-%d").build();

    public static final ExecutorService executorService = new ThreadPoolExecutor(5, 10, 0L,
            TimeUnit.MICROSECONDS, new LinkedBlockingQueue<Runnable>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());

    //固定大小的线程池
    public static final  ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5);


    public static final  ExecutorService singleThreadPool = Executors.newCachedThreadPool();




    @RabbitHandler
    public void handlder(String str , Message message , Channel channel) throws Exception{
        log.info("订单系统----->接受消息 str:{}", str);



        NotifyOrderRequest request = JSON.parseObject(str, NotifyOrderRequest.class);


        log.info("request:{}",JSON.toJSONString(request));

        fixedThreadPool.submit(()->{
            log.info("修改数据库中的订单表中的状态。。。。。");
        });

        executorService.submit(()->{
            log.info("修改数据库中的订单表中的状态。。。。。");
            //修改状态。
        });

    }
}

